package com.heima.kafka.listener;


import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojos.User;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class HelloListener {


    //监听的主题名称 可以写多个
    @KafkaListener(topics = {"topic1","topic2"})
    public void listenerMessage(ConsumerRecord<?,?> record){
        //ConsumerRecord<?,?> record是固定的 接收到的消息从里面拿
//        Object value = record.value();
//        System.out.println("value = " + value);

        Object value = record.value();
        User user = JSON.parseObject((String) value, User.class);
        System.out.println("user = " + user);
    }


}
